package com.jh.tools.update.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.jh.tools.common.notify.NotifyManage;

/**
 * Created by niejiahuan on 2016/5/12.
 * 下载管理类
 */
public class DownLoadManage {
    private static DownLoadManage mDownLoadManage;
    public static DownLoadManage getInstance(){
        return null==mDownLoadManage?mDownLoadManage=new DownLoadManage():mDownLoadManage;
    }
    /**
     * 启动应用下载
     * @param activity
     * @param downUrl
     */
    public void startAppDownLoad(Activity activity,String downUrl,String notifyId,String fileName,int smallIcon,String ticker,String title,boolean DOWNLOAD_SILENT){
        if (null==activity){return;}
        if (null==downUrl){return;}
        NotifyManage.getInstance().notify_progress(activity,Integer.parseInt(notifyId),smallIcon,ticker,title);
        Intent intent = new Intent(activity, DownloadService.class);
        intent.putExtra(UPConstants.APK_DOWNLOAD_URL, downUrl);
        intent.putExtra(UPConstants.DOWNLOAD_FILE_NAME,fileName);
        intent.putExtra(UPConstants.NOTIFYID_UPDATE_PKGNAME,notifyId);
        intent.putExtra(UPConstants.DOWNLOAD_TYPE,DownloadType.DOWNLOAD_APP_SUC);
        intent.putExtra(UPConstants.DOWNLOAD_SILENT,DOWNLOAD_SILENT);
        activity.startService(intent);
    }
    /**
     * 启动文件下载
     * @param activity
     * @param downUrl
     */
    public void startFileDownLoad(Activity activity,String downUrl,String fileName){
        if (null==activity){return;}
        if (null==downUrl){return;}
        Intent intent = new Intent(activity, DownloadService.class);
        intent.putExtra(UPConstants.APK_DOWNLOAD_URL, downUrl);
        intent.putExtra(UPConstants.DOWNLOAD_FILE_NAME,fileName);
        intent.putExtra(UPConstants.NOTIFYID_UPDATE_PKGNAME,-1);
        intent.putExtra(UPConstants.DOWNLOAD_TYPE,DownloadType.DOWNLOAD_FILE_SUC);
        activity.startService(intent);
    }
}
